#include "tmrtmpctrl.h"

TMRTMPCtrl::TMRTMPCtrl(QObject *parent) : QObject(parent)
{
    m_pAVRtmpstreamer = NULL;
    m_pAVRtmplayer = NULL;
}

void TMRTMPCtrl::slot_getVideoLive(QString m_ip,QLabel *pWidget)
{

    QString m_get = QString("%1_out").arg(m_ip);
    qDebug()<<"m_get:"<<m_get;


    static MyGuesterCallback* myGuestCb = new MyGuesterCallback;
    if (m_pAVRtmplayer == NULL) {
        m_pAVRtmplayer = RTMPGuester::Create(*myGuestCb);
        m_pAVRtmplayer->StartRtmpPlay(m_get.toUtf8().data(), (void*)(pWidget->winId()));
    }
}

void TMRTMPCtrl::slot_stopVideoLive()
{

    if (m_pAVRtmplayer) {
        m_pAVRtmplayer->StopRtmpPlay();
        RTMPGuester::Destory(m_pAVRtmplayer);
        m_pAVRtmplayer = NULL;
    }
}

void TMRTMPCtrl::slot_startAudioLive(QString m_ip)
{
    QString m_push = QString("%1_in").arg(m_ip);
    qDebug()<<"m_push:"<<m_push;

    static MyHostCallBack* myHostCb = new MyHostCallBack;
    if (m_pAVRtmpstreamer == NULL) {
        m_pAVRtmpstreamer = RTMPHoster::Create(*myHostCb, 7755);
        m_pAVRtmpstreamer->SetVideoEnable(false);
        m_pAVRtmpstreamer->SetVideoCapturer(NULL/*(void*)(ui->label->winId())*/);
        m_pAVRtmpstreamer->StartRtmpStream(m_push.toUtf8().data(), 0);
    }


//    QString m_get = QString("rtmp://%1/live/robot_out").arg(m_ip);
//    qDebug()<<"m_get:"<<m_get;


//    static MyGuesterCallback* myGuestCb = new MyGuesterCallback;
//    if (m_pAVRtmplayer == NULL) {
//        m_pAVRtmplayer = RTMPGuester::Create(*myGuestCb);
//        m_pAVRtmplayer->StartRtmpPlay(m_get.toUtf8().data(), NULL);
//    }
}

void TMRTMPCtrl::slot_stopAudioLive()
{
    if (m_pAVRtmpstreamer) {
        m_pAVRtmpstreamer->SetVideoCapturer(NULL);
        m_pAVRtmpstreamer->StopRtmpStream();
        RTMPHoster::Destory(m_pAVRtmpstreamer);
        m_pAVRtmpstreamer = NULL;
    }

}
